package com.four.collage.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.collage.entity.Groupgoods;
import com.four.collage.feign.ShopFeginService;
import com.four.collage.service.IAttributeService;
import com.four.collage.service.IGroupgoodsService;
import com.four.collage.vo.GoodsAndAttrVo;
import com.guli.common.utils.R;
import com.guli.common.vo.ManageVo;
import com.guli.common.vo.ParameterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gs
 * @since 2021-12-18
 */
@RestController
@RequestMapping("/groupgoods")
public class GroupgoodsController {

    @Autowired
    private ShopFeginService shopFeginService;

    @Autowired
    private IGroupgoodsService groupgoodsService;


    /**
     * 拼团列表、模糊、精准、分页
     *
     * @param vo
     * @param page
     * @param size
     * @return
     */
    @PostMapping("/list")
    public IPage<Groupgoods> list(@RequestBody GoodsAndAttrVo vo,
                      @RequestParam(value = "page",defaultValue = "1")Integer page,
                      @RequestParam(value = "size",defaultValue = "3")Integer size){

        return groupgoodsService.groupGoodsList(vo,page,size);
    }
    /**
     * 查询所有商品
     * @return
     */
    @GetMapping("/findManageAll")
    public R findManageAll(){
        List<ManageVo> manageVoList=shopFeginService.findAllManage();
        return R.ok().put("manageVoList",manageVoList);
    }

    /**
     * 根据根据选择的id获取改商品信息
     * @param manId
     * @return
     */
    @GetMapping("/findManageById/{manId}")
    public R findManageById(@PathVariable("manId")Integer manId){
        ManageVo manageVo=shopFeginService.getManageById(manId);
        return R.ok().put("manageVo",manageVo);
    }

    /**
     * 根据商品id查询商品属性
     * @param manId
     * @return
     */
    @GetMapping("/findParameterById/{manId}")
    public R findParameterById(@PathVariable("manId")Integer manId){
        List<ParameterVo>parameterVo=shopFeginService.findParameterById(manId);
        return R.ok().put("parameterVo",parameterVo);
    }

    /**
     * 添加拼团商品
     * 商品属性
     * @param goodsAndAttrVo
     * @return
     */
    @PostMapping("/addGroupGoods")
    public R addGroupGoods(@RequestBody GoodsAndAttrVo goodsAndAttrVo){
        groupgoodsService.addGroupGoods(goodsAndAttrVo);
        return R.ok();
    }

    /**
     * 根据拼团商品id查询信息
     * 修改时回显
     * @param grId
     * @return
     */
    @GetMapping("/getGroupgoodsById/{grId}")
    public R getGroupgoodsById(@PathVariable("grId")Integer grId){
        Groupgoods groupgoods=groupgoodsService.getGroupgoodsById(grId);
        return R.ok().put("groupgoods",groupgoods);
    }

    /**
     * 根据拼团商品修改
     * @param grId
     * @return
     */
    @PutMapping("/updateGroupgoods/{grId}")                                                                                                                                              
    public R updateGroupgoods(@PathVariable("grId")Integer grId,@RequestBody GoodsAndAttrVo goodsAndAttrVo){
        groupgoodsService.updateGroupgoods(grId,goodsAndAttrVo);
        return R.ok();
    }

    /**
     * 根据拼团商品id删除商品
     * @param grId
     * @return
     */
    @DeleteMapping("/delGroupgoodsById/{grId}")
    public R delGroupgoodsById(@PathVariable("grId")Integer grId){
        groupgoodsService.delGroupgoodsById(grId);
        return R.ok();
    }
}
